inspector,http: support builtin http request bodies#64369
Open
GrinZero wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
e2e same like: #62915 (comment) |
Collaborator
|
Review requested:
|
cce325b to
7865a8d
Compare
Signed-off-by: GrinZero <774933704@qq.com>
7865a8d to
4bd2033
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64369 +/- ##
========================================
Coverage 90.24% 90.24%
========================================
Files 741 741
Lines 240976 241453 +477
Branches 45408 45494 +86
========================================
+ Hits 217477 217910 +433
- Misses 15070 15087 +17
- Partials 8429 8456 +27
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR supersedes #62915 with the same feature work rebased onto current
main.It adds builtin
http/httpsrequest-body support to network inspection, soNetwork.getRequestPostDatacan return text request bodies while preserving the existing rejection behavior for binary request bodies.It also moves builtin
httpresponse-body tracking to a raw-byte hook beforeIncomingMessagedecoding, so response inspection remains correct even when user code callsresponse.setEncoding(...).In addition, this PR lets
Network.requestWillBeSentcarry JS-provided initiator data captured at request construction time. The C++ inspector side validates structuredinitiator.stackobjects against the inspector protocol schema before forwarding them to DevTools.Problem
Builtin
http/httpsnetwork inspection currently emits request and response lifecycle events, but the builtin client path does not expose request-body bytes to the inspector. As a result,Network.getRequestPostDatacannot return POST data for builtinhttp/httpsrequests.There are two related gaps:
IncomingMessage'data'events are not a stable raw-byte source. If user code callsresponse.setEncoding('utf8'), chunks observed through userland become strings, while the inspector protocol expects byte-oriented payloads.requestWillBeSentuntil request-body state is known means a C++ stack captured at emission time would point into Node.js internals rather than the user call site. The initiator needs to be captured when the request is created and validated before being emitted.Approach
Network.dataSent(...) -> NetworkAgent::getRequestPostData(...)buffering pipeline instead of changing the CDP schema.http.client.request.bodyChunkSenthttp.client.request.bodySenthttp.client.response.bodyChunkReceivedrequestWillBeSentuntil body state is known, sohasPostDatais accurate for both body and body-less requests.initiator.stackwith generated inspector protocol schema support in C++.Behavior
After this change:
httpandhttpsPOST requests with UTF-8 text bodies are available throughNetwork.getRequestPostDatahttpresponse inspection continues to work even if user code callsresponse.setEncoding('utf8')Network.requestWillBeSentreports accuratehasPostDataNetwork.requestWillBeSentcan carry JS-captured initiator stack data from the request construction siteTests
This PR adds and extends coverage in:
test/parallel/test-diagnostics-channel-http.jstest/parallel/test-inspector-network-http.jstest/parallel/test-inspector-emit-protocol-event.jstest/parallel/test-inspector-emit-protocol-event-errors.jsThe updated tests cover:
write()andend()httpandhttpsNetwork.getRequestPostDataresponse.setEncoding('utf8')hasPostDatafor body-less requestsVerification
Validated with the targeted test suite:
Also validated manually with an end-to-end inspector run:
Refs